package com.elegant.code.web;

import com.elegant.code.aop.limit.RateLimit;
import com.elegant.code.domain.User;
import com.elegant.code.service.UserService;
import com.elegant.code.spi.web.auth.AuthConstant;
import com.elegant.code.spi.web.auth.Authorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Valid
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("{id}")
    @RateLimit
    @Authorize(value = {
            AuthConstant.AUTHORIZATION_USER_SERVICE,
            AuthConstant.AUTHORIZATION_PAY_SERVICE
    })
    public User getUser(@PathVariable("id") Integer id){
        return userService.getUser(id);
    }
}
